package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.entity.Orders;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController("AdminOrderController")
@RequestMapping("/admin/order")
@Slf4j
@Api(tags = "管理端订单")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @GetMapping("/conditionSearch")
    @ApiOperation("根据条件查询")
    public Result<PageResult> ConditionSearch(OrdersPageQueryDTO ordersPageQueryDTO){

        PageResult pageResult = orderService.getByConditionSearch(ordersPageQueryDTO);
        return Result.success(pageResult);
    }

    @GetMapping("/statistics")
    @ApiOperation("查询订单状态数量")
    public Result<OrderStatisticsVO> Statistics(){
        OrderStatisticsVO orderStatisticsVO = orderService.Statistics();
        return Result.success(orderStatisticsVO);
    }


    @GetMapping("/details/{id}")
    @ApiOperation("查看订单详细")
    public Result<OrderVO> getOrdersDetails(@PathVariable Long id){
        return Result.success(orderService.getOrdersDetailsById(id));
    }


    @PutMapping("/confirm")
    @ApiOperation("接单")
    public Result ConfirmOrders(@RequestBody OrdersConfirmDTO ordersConfirmDTO){
        orderService.ConfirmOrders(ordersConfirmDTO);
        return Result.success();
    }


    @PutMapping("/rejection")
    @ApiOperation("拒单")
    public Result RejectionOrders(@RequestBody OrdersRejectionDTO ordersRejectionDTO) throws Exception {
        orderService.RejectionOrders(ordersRejectionDTO);
        return Result.success();
    }


    @PutMapping("/cancel")
    @ApiOperation("取消订单")
    public Result CancelOrders(@RequestBody OrdersCancelDTO ordersCancelDTO) throws Exception {
        orderService.CancelOrders(ordersCancelDTO);
        return Result.success();

    }


    @PutMapping("/delivery/{id}")
    public Result DeliveryOrders(@PathVariable Long id){
        orderService.DeliveryOrders(id);
        return Result.success();
    }


    @PutMapping("/complete/{id}")
    public Result CompleteOrders(@PathVariable Long id){
        orderService.CompleteOrders(id);

        return Result.success();
    }

}
